package com.example.demo.model;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;//200成功，-1失败，-2未登录
    private String errorMessage;
    private T data;
    public static <T>Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setData(data);
        return result;
    }
    public static <T>Result<T> fail(T data, String errorMessage) {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setErrorMessage(errorMessage);
        result.setData(data);
        return result;
    }
    public static <T>Result<T> fail(String errorMessage) {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setErrorMessage(errorMessage);
        return result;
    }
    public static <T>Result<T> ulogin() {
        Result<T> result = new Result<>();
        result.setCode(-2);
        result.setErrorMessage("用户未登录");
        return result;
    }
}
